package corba.service;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;

import corba.service.TelephoneService;
import corba.service.TelephoneServiceHelper;

public class TelephoneServiceClient {

	static TelephoneService BSImpl;
	
	public static void main(String[] args) {
		try {
			// create and initialize the ORB
			ORB orb = ORB.init(args, null);

			// get the root naming context
			org.omg.CORBA.Object objRef = orb
					.resolve_initial_references("NameService");
			// Use NamingContextExt instead of NamingContext. This is
			// part of the Interoperable naming Service.
			NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

			// resolve the Object Reference in Naming
			String name = "TelephoneService";
			BSImpl = TelephoneServiceHelper.narrow(ncRef.resolve_str(name));

			System.out.println("Obtained a handle on server object: " + BSImpl);
			String num = BSImpl.receiveTelephone("63");
			System.out.println(num);
		} catch (Exception e) {
			System.out.println("ERROR : " + e);
			e.printStackTrace(System.out);
		}

	}

}
